package com.rui.study.algorithm;

import com.rui.study.algorithm.SORT_1_冒泡排序.BubbleSort;
import com.rui.study.algorithm.SORT_2_插入排序.InsertionSort;
import com.rui.study.algorithm.SORT_3_选择排序.SelectionSort;
import com.rui.study.algorithm.SORT_4_归并排序_分治思想_合并函数.MergeSort;
import com.rui.study.algorithm.SORT_5_快速排序_分治思想_分区函数.QuickSort;
import com.rui.study.algorithm.SORT_6_堆排序.HeapSort;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2018-11-07 09:37
 **/
public class SortTestUtil {

    public static int[] a0 = new int[]{1};
    public static int[] a1 = new int[]{1, 2, 3, 4, 5, 6};      // 最好
    public static int[] a2 = new int[]{6, 5, 4, 3, 2, 1};      // 最坏
    public static int[] a3 = new int[]{3, 6, 1, 4, 2, 5};      // 随机
    public static int[] a4;                                    // 大量元素，最好情况
    public static int[] a5;                                    // 大量元素，最坏情况

    static {
        a4 = new int[10000000];
        a5 = new int[10000000];
        for (int i=0; i<a4.length; i++) {
            a4[i] = i;
            a5[i] = a5.length - i;
        }
    }

    public static void testBubbleSort(int[] a) {
//        PrintUtil.print(a);
        int i = new BubbleSort().bubbleSort(a);
//        PrintUtil.print("冒泡次数: " + i);
//        PrintUtil.print(a);
    }

    public static void testInsertionSort(int[] a) {
//        PrintUtil.print(a);
        new InsertionSort().sort(a);
//        PrintUtil.print(a);
    }

    public static void testSelectionSort(int[] a) {
//        PrintUtil.print(a);
        SelectionSort.sort(a);
//        PrintUtil.print(a);
    }

    public static void testMergeSort(int[] a) {
//        PrintUtil.print(a);
        MergeSort.sort(a);
//        PrintUtil.print(a);
    }

    public static void testQuickSort(int[] a) {
//        PrintUtil.print(a);
        QuickSort.sort(a);
//        PrintUtil.print(a);
    }

    public static void testHeapSort(int[] a) {
//        PrintUtil.print(a);
        HeapSort.sort(a);
//        PrintUtil.print(a);
    }

    public static void main(String[] args) {
        long beginAt = System.currentTimeMillis();
//        testBubbleSort(a4);
        testInsertionSort(a5);
//        testSelectionSort(a4);
//        testMergeSort(a5);
//        testQuickSort(a5);
//        testHeapSort(a5);
        PrintUtil.print("历时：[" + (System.currentTimeMillis() - beginAt) + " ms]");
    }

}
